package com.zephyr.vchcenter.bpm.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import sun.misc.BASE64Encoder;

import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;

public class RandomUtil {
	public static ApplicationContext applicationContext;
	public String getRandomString(int digit){
	NumberFormat formatter = NumberFormat.getNumberInstance();
		formatter.setMaximumIntegerDigits(digit);
		java.util.Random r = new java.util.Random();
		return formatter.format(r.nextInt(digit)).replaceAll("[^0-9]", "");
	}
	public String getUUID(){
		UUID uuid=UUID.randomUUID();
		
		return uuid.toString().replaceAll("-", "");
	}
	public String getSubno(){
		String[] subnos={"beijing","shanghai","wuhan","shenzhen","guangzhou"};
		int i=(int)(Math.random()*4+1);
		return subnos[i];
	}
	public ApplicationContext getApplicationContext(){
		 if(this.applicationContext==null){
			 applicationContext = new ClassPathXmlApplicationContext("applicationContext-servicecpc.xml"); 
		 }
		return applicationContext;
	}
	public List<Voucher> getDaoOperate(Voucher voucher){
		System.out.println(voucher.getChkstate());
		Object obj=SpringHelper.getBean("baseDao");
		IBaseDao baseDao=(IBaseDao)obj;
		List list=baseDao.findByExample(voucher);
		return list;
	}
		
	public Voucher getVoucherById(String id){
		Object obj=SpringHelper.getBean("baseDao");
		IBaseDao baseDao=(IBaseDao)obj;
		Voucher voucher=(Voucher)baseDao.findById("Voucher", id);
		return voucher;
	}
	public byte[] getImg(){
		File file=new File("D:/picTest/00000001.jpg");
		InputStream inps=null;
		byte[] im=new byte[1024];
		try {
			inps=new FileInputStream(file);
			inps.read(im);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return im;
	}
	public static void main(String[] args) {
		System.out.println(UUID.randomUUID());
	}
	
}
